package com.example.demo.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * @author shenb
 * @date 2022-07-08 17:50
 */
public class JsonUtils {

    private static final ObjectMapper mapper = new ObjectMapper();

    public static String toJson(Object any) {
        if (any == null) {
            return null;
        }
        try {
            return mapper.writeValueAsString(any);
        } catch (JsonProcessingException e) {
            throw new IllegalArgumentException("Failed convert object to json string", e);
        }
    }
}
